/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Negocio2;

import DATOS.Usuario;
import javax.swing.JOptionPane;

/**
 *
 * @author Isis Roman
 */
public class GestorUsuario {

    private Usuario user;

    public GestorUsuario() {

        user = new Usuario();
    }
//--------------------------------------------------------------------------//

    public void insertar(String username, String password, String ip, String tipo) {
        if (!existe(username)) {

            //user.setId(id);
            user.setUsername(username);
            user.setPassword(password);
            user.setIp(ip);
            user.setTipo(tipo);
            user.insertar();
        } else {
            JOptionPane.showMessageDialog(null, "EL REGISTRO username YA EXISTE.\n INTENTE NUEVAMENTE", "MENSAJE", JOptionPane.WARNING_MESSAGE, null);
        }

    }
//--------------------------------------------------------------------------//

    public void modificar(int id, String username, String password, String ip, String tipo) {
        if (existe(username)) {

            user.setId(id);
            user.setUsername(username);
            user.setPassword(password);
            user.setIp(ip);
            user.setTipo(tipo);
            user.modificar();
        } else {
            JOptionPane.showMessageDialog(null, "EL REGISTRO NO EXISTE.\n INTENTE NUEVAMENTE", "MENSAJE", JOptionPane.WARNING_MESSAGE, null);
        }
    }
//--------------------------------------------------------------------------//

    public void eliminar(int id) {
        if (existeID(id)) {

            user.setId(id);
            user.eliminar();
        } else {
            JOptionPane.showMessageDialog(null, "EL ID NO EXISTE.\n INTENTE NUEVAMENTE", "MENSAJE", JOptionPane.WARNING_MESSAGE, null);
        }
    }
//--------------------------------------------------------------------------//

    public boolean existe(String username) {
        return user.existe(username);
    }
//--------------------------------------------------------------------------//

    public boolean existeID(int id) {
        return user.existeID(id);
    }
//--------------------------------------------------------------------------//

    public static void main(String[] args) {
        GestorUsuario g = new GestorUsuario();
        Usuario u = new Usuario();
        System.out.println("" + u.listar());
        System.out.println("cant TUPLAS_: " + u.cantTuplas());

        /*g.insertar("isa25", "informatica", "localhost", "usuario");
        System.out.println("" + u.listar());*/

        /*System.out.println("EXISTE = " + String.valueOf(g.existe("isa25")));*/

        /*g.eliminar(2);
        System.out.println("" + u.listar());*/

        /*g.modificar(2,"isa25", "informatica", "localhost", "usuario");
        System.out.println("" + u.listar());*/

    }
//--------------------------------------------------------------------------//
}
